package de.rac.vaadin.framework.ui;

import com.oros.db.AEColumnProperty;
import com.vaadin.data.Item;
import com.vaadin.ui.Field;
import com.vaadin.ui.DateField;

public class DateEditFormField extends EditFormField {
     /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
    private String datePattern;
	public DateEditFormField(String colName,String caption,boolean required,
    		 ResourcePool resource,String datePattern)
     {
    	 super(colName,caption,required,resource);
    	 this.datePattern = datePattern;
     }
	@Override
    public Field getFieldGenerated(Item item) 
    {
		super.getFieldGenerated(item);
        Object val = item.getItemProperty(columnName).getValue();
        if (val!=null && val.getClass()!=java.util.Date.class)
        {
        	val = AEColumnProperty.conversion(java.util.Date.class, val, false);
        }
        DateField dateField = new DateField(caption);
        dateField.setRequired(required);
        dateField.setDateFormat(datePattern);
        dateField.setValue(val);
        setCurrentField(dateField);
        return dateField;
    }
	
}
